package com.thinkgem.book.common.utils;

import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;

import java.math.BigInteger;
import java.security.interfaces.RSAPrivateCrtKey;


/**
 * RSA私钥类
 *
 * @author tonglei
 * @version 1.0.0, 2015-05-14
 */
public class LjRSAPrivateKey implements RSAPrivateCrtKey
{
    private final BigInteger modulus;
    private final BigInteger privateExponent;
    private final BigInteger publicExponent;
    
    private final BigInteger primeP;
    
    private final BigInteger primeQ;
    
    private final BigInteger primeExponentP;
    
    private final BigInteger primeExponentQ;
    
    private final BigInteger crtCoefficient;
    public LjRSAPrivateKey(RSAPrivateCrtKeyParameters paramRSAPrivateCrtKeyParameters)
    {
        this.modulus = paramRSAPrivateCrtKeyParameters.getModulus();
        this.privateExponent = paramRSAPrivateCrtKeyParameters.getExponent();
        this.publicExponent = paramRSAPrivateCrtKeyParameters.getPublicExponent();
        this.primeP = paramRSAPrivateCrtKeyParameters.getP();
        this.primeQ = paramRSAPrivateCrtKeyParameters.getQ();
        this.primeExponentP = paramRSAPrivateCrtKeyParameters.getDP();
        this.primeExponentQ = paramRSAPrivateCrtKeyParameters.getDQ();
        this.crtCoefficient = paramRSAPrivateCrtKeyParameters.getQInv();
    }

    @Override
    public String getAlgorithm(){
        return null;
    }

    @Override
    public String getFormat()
    {
        return "PKCS#8";
    }

    @Override
    public byte[] getEncoded(){
        return new byte[0];
    }

    @Override
    public BigInteger getPublicExponent()
    {
        return this.publicExponent;
    }
    
    @Override
    public BigInteger getPrimeP()
    {
        return this.primeP;
    }
    
    @Override
    public BigInteger getPrimeQ()
    {
        return this.primeQ;
    }
    
    @Override
    public BigInteger getPrimeExponentP()
    {
        return this.primeExponentP;
    }
    
    @Override
    public BigInteger getPrimeExponentQ()
    {
        return this.primeExponentQ;
    }
    
    @Override
    public BigInteger getCrtCoefficient()
    {
        return this.crtCoefficient;
    }

    @Override
    public BigInteger getPrivateExponent(){
        return privateExponent;
    }

    @Override
    public BigInteger getModulus(){
        return modulus;
    }
}
